package edu.bit.water.controller;

import edu.bit.water.entity.MetaCleanProduct;
import edu.bit.water.service.MetaCleanProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/meta_clean_product")
public class MetaCleanProductController {

    @Autowired
    private MetaCleanProductService metaCleanProductService;

    // 查询记录
    @RequestMapping("/select")
    @ResponseBody
    public Map<String, Object> select() {
        Map<String, Object> map = new HashMap<>();
        List<MetaCleanProduct> list = metaCleanProductService.select();
        map.put("status", "success");
        map.put("rows", list);
        return map;
    }

    // 新增记录
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String, Object> insert(MetaCleanProduct metaCleanProduct) {
        return metaCleanProductService.insert(metaCleanProduct);
    }

    // 编辑记录
    @RequestMapping("/update")
    @ResponseBody
    public Map<String, Object> update(MetaCleanProduct metaCleanProduct) {
        return metaCleanProductService.update(metaCleanProduct);
    }

    // 删除记录
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody List<Integer> ids) {
        Map<String, Object> map = new HashMap<>();
        int n = metaCleanProductService.delete(ids);
        if (n == 1) {
            map.put("status", "success");
        } else {
            map.put("status", "failed");
        }
        return map;
    }

    // 删除全部子页面数据
    @RequestMapping("/delete_sub")
    @ResponseBody
    public Map<String, Object> deleteSub(@RequestBody List<Integer> ids) {
        Map<String, Object> map = new HashMap<>();
        int n = metaCleanProductService.deleteSub(ids);
        if (n == 1) {
            map.put("status", "success");
        } else {
            map.put("status", "failed");
        }
        return map;
    }

    // 元数据标准状态发生改变，改变相应功能页面的标准状态
    @RequestMapping("/update_status")
    @ResponseBody
    public void updateStatus(String standardNumber, String standardStatus) {
        metaCleanProductService.updateStatus(standardNumber, standardStatus);
    }
}
